﻿using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _058.Excel操作
{
	internal class Class1
	{

		// using Excel = Microsoft.Office.Interop.Excel;
		//public void MergeExcel(string file1, string file2, string outputFile)
		//{
		//	// 创建一个新的Excel应用程序
		//	Excel.Application excelApp = new Excel.Application();
		//	// 打开第一个文件
		//	Excel.Workbook workbook1 = excelApp.Workbooks.Open(file1);
		//	// 获取第一张表格
		//	Excel._Worksheet worksheet1 = workbook1.Sheets[1];
		//	// 打开第二个文件
		//	Excel.Workbook workbook2 = excelApp.Workbooks.Open(file2);
		//	// 获取第二张表格 
		//	Excel._Worksheet worksheet2 = workbook2.Sheets[1];
		//	// 新建输出文件并获取其工作簿和工作表对象 
		//	var outputWorkbook = excelApp.Workbooks.Add();
		//	var outputWorksheets = (Excel._Worksheet)outputWorkbook.ActiveSheet;

		//	int rowCounter = 0;
		//	for (int i = 1; i <= worksheet1.UsedRange.Rows.Count; i++)
		//	{
		//		rowCounter++;
		//		outputWorksheets.Cells[rowCounter, 1] = worksheet.Cells[i, 1].Value.ToString();
		//		outputWorksheets.Cells[rowCounter, 2] = worksheet.Cells[i, 2].Value.ToString();
		//	}
		//	for (int j = 2; j <= worksheet.UsedRange.Rows.Count; j++)
		//	{
		//		rowCounter++;
		//		outputWorksheets.Cells[rowCounter, 3] = worksheet.Cells[j, 3].Value.ToString();
		//	}

		//	//保存输出文件并关闭所有打开的工作簿和应用程序 
		//	outputWorkbook.SaveAs(outputFile);
		//	workbook.Close(false);
		//	workBook.ReleaseComObject();

		//}
	//}
}

}
